package com.wnhz.work.yz.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.utils.LogUtil;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    private static final String TAG = "WXPayEntryActivity";

    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);

        api = WXAPIFactory.createWXAPI(this, "wxb6172005514ce1e7");
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {

    }

    //处理微信支付回调
    @Override
    public void onResp(BaseResp resp) {
        Log.e("==微信支付回调的状态码 ==", "onPayFinish, errCode = " + resp.errCode);
        if (resp.errCode == 0) {
            MyApplication.getInstance().isWXPay = resp.errCode;
            LogUtil.e("------微信支付状态------- ", "支付成功");
        } else if (resp.errCode == -1) {
            MyApplication.getInstance().isWXPay = resp.errCode;
            LogUtil.e("------微信支付状态------- ", "支付失败");
        }else if (resp.errCode == -2) {
            MyApplication.getInstance().isWXPay = resp.errCode;
            LogUtil.e("------微信支付状态------- ", "支付取消");
        }
        finish();
    }
}